<!DOCTYPE html>
<html>
<head>
    <title>搜索系统菜单</title>
    {include file="common/inc_meta" /}
</head>
<body>
 <div id="wrapper">
    {include file="common/inc_menu" /}
       <div id="page-wrapper" class="gray-bg">
          {include file="common/inc_top" /}
            <div class="row wrapper border-bottom white-bg page-heading" style="padding-top:20px;font-weight: normal;">
                <div class="col-sm-4">
                    <h2 style="margin-bottom:10px;">搜索系统菜单/节点</h2>
                    <ol class="breadcrumb">
                        <li><a href="{$admin.index_page}">主页</a></li>
                        <li><a>菜单</a></li>
                        <li class="active"><strong>搜索</strong></li>
                    </ol>
                </div>
                <div class="col-lg-2"></div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">

                    <div class="row">
                        <div class="col-lg-12">
                            <div class="ibox float-e-margins">
                                <div class="ibox-content">
                                    <h2>来自: <span class="text-navy">“{$word}”</span> 的搜索结果</h2>
                                    <div class="search-form">
                                        <div class="input-group">
                                            <input type="text" placeholder="输入关键词" id="searchValue" value="{$word}" class="form-control input-lg" autocomplete="off">
                                            <div class="input-group-btn">
                                                <button class="btn btn-lg btn-primary" type="button" id="searchBtn">搜索</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="SearchResultBox">

                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <div class="text-center">
                                        <div class="btn-group" id="pagebox"></div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>

            </div>
     {include file="common/inc_footer" /}
     </div>
 </div>
<!-- Mainly scripts -->
{include file="common/inc_jsfile" /}

<script>
var _p = {$page}, _keyword = '{$word}';
$(function(){
  //搜索
  $("#searchBtn").click(function(){
     _keyword = $.trim($("#searchValue").val());
     if(_keyword != '' && _keyword.length > 0)
     {
       //window.location.href = "{:url('admin/index/search')}?top_search=" + _keyword;
       $(".text-navy").html('“' + _keyword + '”');
       _p = 1;
       getPageData();
     }
  });
  getPageData();
  $("#searchValue").focus();
  $("#searchValue").select();
});
//加载数据
function getPageData(){
 _Admin.ajax("{:url('admin/index/search')}",{page:_p,word:_keyword},function(d){
   if(d.err == '0')
   {
      $('#SearchResultBox').empty();
      var _wwwurl = "{$site.weburl}";
       $.each(d.list, function(i,v){  
         if(v.pid <= 0)
         {
           var html = '<div class="hr-line-dashed"></div>\
                      <div class="search-result">\
                         <h3><a href="javascript:void(0);">' + v.title + '</a></h3>\
                         <a href="javascript:void(0);" class="search-link">' + v.url + '</a>\
                      </div>';
         }else{
           var html = '<div class="hr-line-dashed"></div>\
                      <div class="search-result">\
                         <h3><a href="' + _wwwurl + v.url + '">' + v.title + '</a></h3>\
                         <a href="' + _wwwurl + v.url + '" class="search-link" target="_blank">' + _wwwurl + v.url + '</a>\
                      </div>';
         }
         $('#SearchResultBox').append(html);  
      });
      LoadPageBody(d.page, d.limit, d.total);  
   }else{
      $('#SearchResultBox').empty();
      $('#pagebox').hide();
      $('#SearchResultBox').append('<div style="padding:30px 0px;color:#ff0000;">' + d.msg + '</div>');
   }
 });  
}
//参数 当前页 / 每页显示数量 / 总记录数
function LoadPageBody(_page = 0, _limit = 0, _count = 0)
{
 Laypage.render({
    elem: 'pagebox'
    ,curr: _page
    ,limit:_limit
    ,count: _count
    ,layout: ['count', 'prev', 'page', 'next', 'skip']
    ,jump: function(obj, first){
      _p = obj.curr;
      if(!first) getPageData();
    }
 });  
}
</script>
</body>
</html>
